/**
 * Copyright (c) 时间, Tal.Ben 袁东昊 (ydonghao2@gmail.com).
 *
 * 版权
 */
package com.talben.soudian.ui;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.talben.soudian.R;
import com.talben.soudian.player.Player;

/**
 * @Title: VideoPlayActivity.java
 * @Package com.talben.soudian.ui
 * @Description: TODO(添加描述)
 * @author Tal.Ben
 * @date 2015年6月13日 下午9:29:27
 * @version v1.0
 */
public class VideoPlayActivity extends Activity {

	@InjectView(R.id.surfaceView1)
	SurfaceView surfaceView;  
	@InjectView(R.id.btnPause)
    Button btnPause;
	@InjectView(R.id.btnPlayUrl)
    Button btnPlayUrl;
	@InjectView(R.id.btnStop)
    Button btnStop;  
	@InjectView(R.id.skbProgress)
    SeekBar skbProgress;  
    Player player; 	
    
    @Override
    public void onCreate(Bundle savedInstanceState) { 
    	super.onCreate(savedInstanceState); 
        setContentView(R.layout.temp);  
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		ButterKnife.inject(this);
		initView();
	}
	
    public void initView() {
		player = new Player(surfaceView, skbProgress); 
		
		btnPlayUrl.setOnClickListener(new ClickEvent()); 
		btnPause.setOnClickListener(new ClickEvent()); 
		btnStop.setOnClickListener(new ClickEvent()); 
    }
	
	class ClickEvent implements OnClickListener {  
		  
        @Override  
        public void onClick(View arg0) {  
            if (arg0 == btnPause) {  
                player.pause();  
            } else if (arg0 == btnPlayUrl) {  
                String url="http://103.41.141.77/youku/69736B1875D3F7B891D916A9F/0300080100514CDCC117ED01BB9D9D61CCFE71-3919-AADA-2135-9ACFAF0A1691.mp4";  
                player.playUrl(url);  
            } else if (arg0 == btnStop) {  
                player.stop();  
            }  
        }  
    }  
	
	class SeekBarChangeEvent implements SeekBar.OnSeekBarChangeListener {  
        int progress;  
  
        @Override  
        public void onProgressChanged(SeekBar seekBar, int progress,  
                boolean fromUser) {  
            // 原本是(progress/seekBar.getMax())*player.mediaPlayer.getDuration()
            this.progress = progress * player.mediaPlayer.getDuration()  
                    / seekBar.getMax();  
        }  
  
        @Override  
        public void onStartTrackingTouch(SeekBar seekBar) {  
  
        }  
  
        @Override  
        public void onStopTrackingTouch(SeekBar seekBar) {  
            // seekTo()的参数是相对与影片时间的数字，而不是与seekBar.getMax()相对的数字  
            player.mediaPlayer.seekTo(progress);  
        }  
    }
	
}

